﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef Application_h__
#define Application_h__
#include "IApplication.h"
#include <windows.h>
#include <cinttypes>
#include "IProcessMsg.h"

namespace SkyEngine2d
{
	
	class IApplicationView;
	class ApplicationView;
	class InputEventDispatcher;
	class GameWorld;

	//! 应用程序的实例
	class SGE_API Application
		:public IApplication, public IProcessMsg
	{
	public:
		static IApplication* getInstance();
		virtual int run() override;
		virtual void setPerFrameInterval(double interval)override;
		virtual void setAppDelegte(IAppDelegate* app_delegate)override;
		virtual IApplicationView* getAppView()const override;
		virtual void setWinMsgFilter(const WinMsgFilter & filter) override;
		~Application();
	
		virtual const std::wstring& getAppDir() override;
	
	protected:
		Application();
	private:
		//! 初始化应用程序 
		bool initApp();
		//! 清理应用程序 
		void clearApp();
	private:
		//每帧的间隔
		LARGE_INTEGER  m_animationInterval;
		//应用程序代理
		IAppDelegate* m_appDelegate;
		//应用程序视图
		ApplicationView* m_applicationView;
		//每秒的计数
		int64_t  m_perSecondCount;
		//输入事件分发器
		InputEventDispatcher* m_inputEventDispater;
		//是否最小化窗口
		bool   m_isMinWindows; 
		WinMsgFilter m_filter;
		//游戏世界
		GameWorld* m_gameWorld;
	public:
		virtual LRESULT processMsg(HWND hwnd, UINT msg, WPARAM wParam, LPARAM IParam) override;
	
	};
}

#endif // Application_h__